<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Dliver_m extends FOX_Model
{

	function __construct ()
	{
		parent::__construct();
	}

    /**
     * @param $deliver_id
     * @return mixed
     * 查询单条
     */
    public function get_delivers_by_id($deliver_id){
        $query = $this->db
            ->select('*')
            ->get_where('delivers', array('deliver_id'=>$deliver_id));
        return $query->row_array();
    }

    public function get_delivers_by_order_id($order_id){
        $query = $this->db
            ->select('*')
            ->get_where('delivers', array('order_id'=>$order_id));
        return $query->row_array();
    }

    /**
     * @param $deliver_id
     * @param $data
     * @return bool
     * 修改商家信息
     */
    public function sava_delivers($deliver_id,$data){

        $this->db->where('deliver_id',$deliver_id);
        $this->db->update('delivers', $data);
        return ($this->db->affected_rows() > 0) ? TRUE : FALSE;
    }

    /**
     * @param $data
     * @return bool
     * 新增商家
     */
    public function add_delivers($data){

        $this->db->insert('delivers',$data);
        if($this->db->affected_rows() > 0){
            return $this->db->insert_id();
        }else{
            return false;
        }
    }

    /**
     * @return mixed
     * 查询所有商家
     */
    public function get_all_delivers(){
        $this->db->select('*');
        $this->db->from('delivers');
        $query = $this->db->get();
        if($query->num_rows() > 0){
            return $query->result_array();
        }
    }


    /**
     * 获取启用的规则
     */
    public function get_delivers_by($map = "status=1"){
        $sql = "SELECT * FROM {$this->db->dbprefix}delivers  where $map ORDER BY o asc";
        $query=$this->db->query($sql);
        if($query->num_rows() > 0){
            return $query->result_array();
        }
    }

    /**
     * @param $where
     * @return bool
     * 删除商家
     */
    public function delete_delivers_by($where){
        $this->db->where($where)->delete('delivers');
        return ($this->db->affected_rows() > 0) ? TRUE : FALSE;
    }

}
